<!--
 * @Descripttion: 自提点列表
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-04-28 16:00:04
-->
<template>
  <div class="lb-order-manage">
    <top-nav />
    <div class="page-main">
      <lb-tips>
        <p class="f-title c-title">买家上门自提功能</p>
        <p>上门自提功能应用场景：买家可以就近选择你预设的自提点，下单后你需要尽快将商品配送至指定自提点，需填写自提地址，方便买家定位</p>
      </lb-tips>
      <el-row class="page-top-operate">
          <lb-button  type="primary" icon='el-icon-plus' @click="$router.push('/malls/store')">{{$t('menu.StoreAdd')}}</lb-button>
      </el-row>
      <div class="page-search-form">
          <el-form @submit.native.prevent :inline="true" :model="searchForm" ref="searchForm">
            <el-form-item label="输入查询" prop="title">
              <el-input v-model="searchForm.title" placeholder="请输入自提点名称/地址" style="width:200px"></el-input>
            </el-form-item>
            <el-form-item>
              <lb-button size="medium" type="primary" icon="el-icon-search" style="margin-right:5px" @click="getTableDataList(1)">{{$t('action.search')}}</lb-button>
              <lb-button size="medium" icon="el-icon-refresh-left" style="margin-right:5px" @click="resetForm('searchForm')">{{$t('action.reset')}}</lb-button>
            </el-form-item>
          </el-form>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
        style="width: 100%"
      >
        <el-table-column prop="title" label="自提点名称"></el-table-column>
        <el-table-column prop="province" label="省份"></el-table-column>
        <el-table-column prop="city" label="城市"></el-table-column>
        <el-table-column prop="area" label="地区"></el-table-column>
        <el-table-column prop="address" label="地址"></el-table-column>
        <el-table-column prop="mobile" label="联系电话"></el-table-column>
        <el-table-column prop="status" label="是否营业">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              :active-value="1"
              :inactive-value="0"
              @change="upperAndDel(scope.row.id,scope.row.status)"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180px">
          <template slot-scope="scope">
            <div class="table-operate">
              <lb-button
                size="mini"
                plain
                type="primary"
                @click="$router.push('/malls/store?id=' + scope.row.id)"
              >{{$t('action.edit')}}</lb-button>
              <lb-button
                size="mini"
                plain
                type="danger"
                @click="confirmDel(scope.row.id,-1)"
              >{{$t('action.delete')}}</lb-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <lb-page
        :batch="false"
        :page="searchForm.page"
        :pageSize="searchForm.limit"
        :total="total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      >
      </lb-page>
    </div>
  </div>
</template>

<script>
// import pubic from '@/utils/public'
export default {
  data () {
    return {
      loading: false,
      searchForm: {
        title: '',
        page: 1,
        limit: 10
      },
      tableData: [],
      total: 0
    }
  },
  activated () {
    this.getTableDataList()
  },
  methods: {
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let {searchForm} = this
      this.$api.storeList(searchForm).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.data.data
          this.total = res.data.total
        }
      })
    },
    confirmDel (id, status) {
      this.$confirm(this.$t('tips.confirmDelete'), this.$t('tips.reminder'), {
        confirmButtonText: this.$t('action.comfirm'),
        cancelButtonText: this.$t('action.cancel'),
        type: 'warning'
      }).then(() => {
        this.upperAndDel(id, status)
      }).catch(() => {

      })
    },
    async upperAndDel (id, status) {
      this.$api.storeStatusUpdate({id, status}).then(res => {
        if (res.code === 200) {
          this.$message.success(this.$t(status === -1 ? 'tips.successDel' : 'tips.successOper'))
          if (status === -1) {
            this.searchForm.page = this.searchForm.page < Math.ceil((this.total - 1) / this.searchForm.limit) ? this.searchForm.page : Math.ceil((this.total - 1) / this.searchForm.limit)
            this.getTableDataList()
          }
        } else {
          if (status === -1) return
          this.getTableDataList()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
